# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=distorm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.0
pkgrel=1
pkgdesc="Powerful disassembler library for x86/AMD64 (mingw-w64)"
arch=('any')
url="https://github.com/gdabah/distorm"
license=('GPL3')
#depends=("${MINGW_PACKAGE_PREFIX}-python2")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python2")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/gdabah/distorm/archive/v${pkgver}.tar.gz
        Makefile
        001-detect-mingw-python.patch)
sha256sums=('887e12671aafcb198ba90fa9de5a81fc0a2e682f420618ef7ba6cc4e84c04438'
            'a35882522a38d3ab685fd33dba746baf3704e6932e1c5707a8bd97e37ac51766'
            'bbe2c5bc9a088f93017b0f730b9b8730e943855a89085863bc674b528b9f59bb')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-detect-mingw-python.patch
  cp -f ${srcdir}/Makefile make/win32/
}

build() {
  cd ${_realname}-${pkgver}
  make -C make/win32
}

package() {
  cd ${_realname}-${pkgver}

  make -C make/win32 DESTDIR="${pkgdir}" INSTALL_PREFIX=${MINGW_PREFIX} install
  
  sed -e '1i#!/usr/bin/env python2' -i python/distorm3/sample.py
  install -Dm 755 python/distorm3/sample.py "${pkgdir}${MINGW_PREFIX}/bin/disasm.py"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" -O1
  
  install -Dm 644 include/*.h -t "${pkgdir}${MINGW_PREFIX}/include"
  install -Dm 644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
